home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / TXTHGT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.5 KB  |  51 lines

  1.  
  2. /* txthgt.c --- textheight, BIBLE p. 861 */
  3.  
  4. #include <graphics.h>
  5. #define ESC '\033'                     /* The ASCII code for Escape */
  6. main()
  7. {
  8.     int graphdriver = DETECT, graphmode, xmax, ymax,
  9.                         xsize, ysize, c, x, y;
  10.     char outstr[2] = " ";
  11.                 /* Detect and initialize graphics system */
  12.     initgraph(&graphdriver, &graphmode, "c:\\turboc");
  13.                 /* Define a viewport */
  14.     xmax = getmaxx();
  15.         ymax = getmaxy();
  16.         xsize = xmax - 100;
  17.         ysize = ymax - 60;
  18.         outtextxy(10, 10, "Press Esc followed by any other key to exit");
  19.     setviewport(50, 30, xsize+50, ysize+30, 1);
  20.         setfillstyle(SOLID_FILL, RED);
  21.         bar3d(0, 0, xsize, ysize, 0, 1);
  22.         setcolor(YELLOW);
  23.         settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  24.         /* Read characters and print them to the viewport.
  25.          * When the edge of the viewport is reached, move
  26.          * down by the height of the character plus 4 pixels.
  27.          * Exit the loop when user presses the Escape key. */
  28.     settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
  29.     x = 4;
  30.     y = textheight("H") + 4;
  31.     moveto(x, y);
  32.     while ((c = getch()) != ESC)
  33.     {
  34.         outstr[0] = c;
  35.         if ((c == '\r') || (x + textwidth(outstr)) > xsize)
  36.             /* Advance to the next line in the viewport */
  37.             {
  38.             x = 4;
  39.             y += textheight("H");
  40.             moveto(x, y);
  41.         }
  42.         /* Print text. Don't print carriage return */
  43.         if (c != '/r')
  44.             outtext(outstr);
  45.         x += textwidth(outstr);
  46.     }
  47.             /* Wait for final key press before exiting */
  48.     getch();
  49.             /* Close graphics system when done */
  50.     closegraph();
  51. }